package com.zbkj.admin.controller.brand;

import com.zbkj.common.annotation.LogControllerAnnotation;
import com.zbkj.common.enums.MethodType;
import com.zbkj.common.page.CommonPage;
import com.zbkj.common.request.*;
import com.zbkj.common.response.StoreClerkPageDataBrandResponse;
import com.zbkj.common.response.StoreClerkPageDataResponse;
import com.zbkj.common.response.StoreClerkRecordBrandPageDataResponse;
import com.zbkj.common.response.StoreClerkRecordPageDataResponse;
import com.zbkj.common.result.CommonResult;
import com.zbkj.service.service.StoreClerkRecordService;
import com.zbkj.service.service.StoreClerkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * 品牌商店小二管理 前端控制器
 */
@Slf4j
@RestController
@RequestMapping("api/admin/brand/store/clerk")
@Api(tags = "店小二管理") //配合swagger使用

public class BrandStoreClerkController {

    @Autowired
    private StoreClerkService storeClerkService;

    @Autowired
    private StoreClerkRecordService storeClerkRecordService;


    /**
     * 分页显示店小二设置表
     *
     * @param request          搜索条件
     * @param pageParamRequest 分页参数
     * @author dazongzi
     * @since 2025-06-27
     */
    //@PreAuthorize("hasAuthority('platform:activitystyle:list')")
    @ApiOperation(value = "分页列表") //配合swagger使用
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public CommonResult<CommonPage<StoreClerkPageDataBrandResponse>> getList(@Validated StoreClerkSearchBrandRequest request,
                                                                      @ModelAttribute PageParamRequest pageParamRequest) {
        CommonPage<StoreClerkPageDataBrandResponse> storeClerkCommonPage = CommonPage.restPage(storeClerkService.getListBrand(request, pageParamRequest));
        return CommonResult.success(storeClerkCommonPage);
    }

    /**
     * 新增店小二设置表
     * @param storeClerkSaveRequest 新增参数
     * @author dazongzi
     * @since 2025-06-27
     */
    @ApiOperation(value = "新增")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public CommonResult<String> save(@RequestBody @Validated StoreClerkSaveBrandRequest storeClerkSaveRequest) {
        if(storeClerkService.createBrand(storeClerkSaveRequest)) {
            return CommonResult.success();
        } else {
            return CommonResult.failed();
        }
    }

    @ApiOperation(value = "创建店小二自动分配商户")
    @RequestMapping(value = "/auto/create", method = RequestMethod.POST)
    public CommonResult<String> autoCreate(@RequestBody @Validated StoreClerkAutoCreateBrandRequest storeClerkSaveRequest) {
        if(storeClerkService.autoCreateBrand(storeClerkSaveRequest)) {
            return CommonResult.success();
        } else {
            return CommonResult.failed();
        }
    }

    @LogControllerAnnotation(intoDB = true, methodType = MethodType.DELETE, description = "批量删除店小二")
    @ApiOperation(value = "批量删除店小二")
    @RequestMapping(value = "/batch/delete", method = RequestMethod.POST)
    public CommonResult<String> batchDelete(@RequestBody @Validated CommonBatchRequest request) {
        if (storeClerkService.batchDeleteBrand(request.getIdList())) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    /**
     * 分页显示店小二记录表
     *
     * @param request          搜索条件
     * @param pageParamRequest 分页参数
     * @author dazongzi
     * @since 2025-06-27
     */
    //@PreAuthorize("hasAuthority('platform:activitystyle:list')")
    @ApiOperation(value = "分配记录列表") //配合swagger使用
    @RequestMapping(value = "/record/list", method = RequestMethod.GET)
    public CommonResult<CommonPage<StoreClerkRecordBrandPageDataResponse>> getRecordList(@Validated StoreClerkRecordBrandSearchRequest request,
                                                                            @ModelAttribute PageParamRequest pageParamRequest) {
        return CommonResult.success(CommonPage.restPage(storeClerkRecordService.getListBrand(request, pageParamRequest)));
    }

    @LogControllerAnnotation(intoDB = true, methodType = MethodType.DELETE, description = "批量删除店小二")
    @ApiOperation(value = "批量删除分配记录")
    @RequestMapping(value = "/record/batch/delete", method = RequestMethod.POST)
    public CommonResult<String> batchDeleteRecord(@RequestBody @Validated CommonBatchRequest request) {
        if (storeClerkRecordService.batchDeleteBrand(request.getIdList())) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

}



